import pygame
from MainWindow import MainWindow
from Person import Person
from S_Wall import S_Wall
from D_Wall import D_Wall
from Door import Door
from Door_Person import Door_Person
from Gear import Gear
from Many_Spike import Many_Spike
class MainGame_three(MainWindow):

    def __init__(self):
        super().__init__()

        self.person = Person(930, 110)  # 人物初始化
        self.S_Walls.extend([
            S_Wall(0, 600, 1000, 200),
            S_Wall(650,0,40,550),
            S_Wall(960, 0, 40, 600),
            S_Wall(740,470,220,40),
            S_Wall(690, 380, 220, 40),
            S_Wall(740, 290, 220, 40),
            S_Wall(690, 200, 220, 40),
            S_Wall(740, 110, 220, 40),
            ])  # 静态墙初始化 [x,y]
        self.D_Walls.extend([
            D_Wall(-1000,0,1000,600,'x',2.5,False,2000)
        ])

        self.Many_spike.extend([
            Many_Spike(0,0)
        ])
        self.Gear.extend([
            Gear(600,615,-5)
        ])
        self.all_sprites.add(self.person)
        for wall in self.S_Walls:
            self.obstacles.add(wall)
        for wall in self.D_Walls:
            self.D_obstacles.add(wall)

        self.door = Door(900, 600)  # 出口初始化
        self.door_person = Door_Person(self.door.rect.x, self.door.rect.y)  # 出口动画初始化
    def StartGame(self):
        super().Start()
        while True:
            dt = self.clock.tick(60) / 1000  # 获取delta time用于平滑移动
            self.GetEvent()
            self.update(dt)
            self.render()
            self.brith()
            pygame.display.flip()
            #后续添加判断人门图片是否存在，然后结束本关卡。
            if not self.door_person.alive:
                break
    # 渲染窗口
    def render(self):
        super().render()
        for d_wall in self.D_obstacles:
            if d_wall.alive == True:
                d_wall.move_img_display(self.window)
            else:
                if d_wall.visible == False:
                    self.window.blit(d_wall.image,d_wall.rect)
        self.draw_mute_button()  # 绘制静音按钮
        if not self.person.rect.colliderect(self.door.rect):
            self.all_sprites.draw(self.window)
            self.door.Door_display(self.window)
        else:
            self.reached_door = True  # 设置碰撞状态
            self.door_person.img_move('y',3)
            self.door_person.move_img_display(self.window)